<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(to right, #0033cc, #66ccff);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 800px;
            margin: 50px auto;
            padding: 30px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        .page-title {
            text-align: center;
            margin-bottom: 30px;
            font-size: 2.5em;
            color: #333;
            font-weight: bold;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            font-weight: bold;
            margin-bottom: 5px;
            display: block;
            font-size: 1.2em;
            color: #333;
        }

        .form-control {
            border-radius: 8px;
            border: 1px solid #ddd;
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
            padding: 10px;
            font-size: 1em;
        }

        .form-check {
            margin-bottom: 10px;
            display: flex;
            align-items: center;
        }

        .form-check input {
            margin-right: 10px;
        }

        .tag-container {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }

        .form-check-label {
            font-size: 0.9em;
            color: #333;
        }

        .btn-submit {
            display: block;
            width: 100%;
            padding: 15px;
            background-color: #007bff;
            border: none;
            color: white;
            font-size: 1.2em;
            cursor: pointer;
            border-radius: 8px;
            text-align: center;
            transition: background-color 0.3s ease;
        }

        .btn-submit:hover {
            background-color: #0056b3;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
    <div class="container">
        <div class="page-title">上传歌曲</div>
        <form id="uploadForm" enctype="multipart/form-data">
            <div class="form-group">
                <label for="fileUpload">文件上传：</label>
                <input type="file" id="fileUpload" name="filename" class="form-control" />
            </div>

            <div class="form-group">
                <label for="singer">歌手名:</label>
                <input type="text" id="singer" name="singer" placeholder="请输入歌手名" class="form-control" />
            </div>

            <div class="form-group">
                <label>音乐标签:</label>
                <div class="tag-container">
                    <!-- 标签选项 -->
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="ancientStyle" name="tags" value="古风" />
                        <label class="form-check-label" for="ancientStyle">古风</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="nationalStyle" name="tags" value="国风" />
                        <label class="form-check-label" for="nationalStyle">国风</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="animeStyle" name="tags" value="二次元" />
                        <label class="form-check-label" for="animeStyle">二次元</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="pop" name="tags" value="流行" />
                        <label class="form-check-label" for="pop">流行</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="rock" name="tags" value="摇滚" />
                        <label class="form-check-label" for="rock">摇滚</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="jazz" name="tags" value="爵士" />
                        <label class="form-check-label" for="jazz">爵士</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="classical" name="tags" value="古典" />
                        <label class="form-check-label" for="classical">古典</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="hipHop" name="tags" value="嘻哈" />
                        <label class="form-check-label" for="hipHop">嘻哈</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="blues" name="tags" value="蓝调" />
                        <label class="form-check-label" for="blues">蓝调</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="folk" name="tags" value="民谣" />
                        <label class="form-check-label" for="folk">民谣</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="electronic" name="tags" value="电子" />
                        <label class="form-check-label" for="electronic">电子</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="dance" name="tags" value="舞曲" />
                        <label class="form-check-label" for="dance">舞曲</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="opera" name="tags" value="歌剧" />
                        <label class="form-check-label" for="opera">歌剧</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="instrumental" name="tags" value="器乐" />
                        <label class="form-check-label" for="instrumental">器乐</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="reggae" name="tags" value="雷鬼" />
                        <label class="form-check-label" for="reggae">雷鬼</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="metal" name="tags" value="金属" />
                        <label class="form-check-label" for="metal">金属</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="soul" name="tags" value="灵魂" />
                        <label class="form-check-label" for="soul">灵魂</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="country" name="tags" value="乡村" />
                        <label class="form-check-label" for="country">乡村</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="rnb" name="tags" value="R&B" />
                        <label class="form-check-label" for="rnb">R&B</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="alternative" name="tags" value="另类" />
                        <label class="form-check-label" for="alternative">另类</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="ambient" name="tags" value="氛围" />
                        <label class="form-check-label" for="ambient">氛围</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="japanese" name="tags" value="日语" />
                        <label class="form-check-label" for="japanese">日语</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="folkRock" name="tags" value="民谣摇滚" />
                        <label class="form-check-label" for="folkRock">民谣摇滚</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="gospel" name="tags" value="福音" />
                        <label class="form-check-label" for="gospel">福音</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="trance" name="tags" value="迷幻" />
                        <label class="form-check-label" for="trance">迷幻</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="newAge" name="tags" value="新世纪" />
                        <label class="form-check-label" for="newAge">新世纪</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="latin" name="tags" value="拉丁" />
                        <label class="form-check-label" for="latin">拉丁</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="synthwave" name="tags" value="合成波" />
                        <label class="form-check-label" for="synthwave">合成波</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="industrial" name="tags" value="工业" />
                        <label class="form-check-label" for="industrial">工业</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="love" name="tags" value="爱情" />
                        <label class="form-check-label" for="love">爱情</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="english" name="tags" value="英语" />
                        <label class="form-check-label" for="english">英语</label>
                    </div>
                    <div class="form-check">
                        <input type="checkbox" class="form-check-input" id="korean" name="tags" value="韩语" />
                        <label class="form-check-label" for="korean">韩语</label>
                    </div>

                </div>
            </div>

            <button type="button" id="submitBtn" class="btn-submit">上传</button>
        </form>
    </div>

    <script>
        $(document).ready(function () {
            $('#submitBtn').click(function () {

                // 获取表单数据
                var formData = new FormData($('#uploadForm')[0]);

                // 提取文件
                var filename = $('#fileUpload')[0].files[0];

                // 提取歌手名
                var singer = $('#singer').val();

                // 提取选中的标签
                var tags = [];
                $('input[name="tags"]:checked').each(function () {
                    tags.push($(this).val());
                });

                // 创建一个新的对象来存放提取的数据
                var data = {
                    filename: filename,
                    singer: singer,
                    tags: tags
                };

                // 将数据转换为 FormData 对象
                var uploadData = new FormData();
                uploadData.append('filename', filename);
                uploadData.append('singer', singer);
                tags.forEach(function (tag) {
                    uploadData.append('tags[]', tag); // 注意这里使用了数组语法
                });

                console.log(filename);
                console.log(singer);
                console.log(tags);

                // 发送 AJAX 请求
                $.ajax({
                    url: '/music/upload',
                    type: 'POST',
                    data: uploadData,
                    processData: false,
                    contentType: false,
                    success: function (result) {
                        if (result != null && result.code == 200 && result.data == true) {
                            alert('音乐上传成功！');
                            location.href = "list.html";
                        } else {
                            alert(result.errMsg);
                        }

                    }
                });
            });
        });
    </script>
</body>

</html>